package com.zfc.service.imp;

import com.zfc.dao.UserDao;
import com.zfc.entity.User;
import com.zfc.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Slf4j //引入日志
/**
 * service层
 */
public class UserServiceImp implements UserService {
    @Autowired
    UserDao userDao;

    @Override
    //如果其他bean调用这个方法,在其他bean中声明事务,那就用事务.如果其他bean没有声明事务,那就不用事务.
    @Transactional(propagation = Propagation.SUPPORTS)
    public User login(User user) {
        User userDB = null;
        try {
            userDB = userDao.getOne(user);

        }catch (Exception e){
            e.printStackTrace();
            log.info("调用userDao.getOne失败！");
        }

        return userDB;
    }
}
